package database;

public class Student {
	private Integer id;
	private String name;
	private Integer sex;
	private Integer grade;
	private Integer c_id;
	private Integer m_id;
	private String classs;
	private String company;
	private String city;
	private String job;
	private Double money;
	private Integer type;
	
	public Student() {
		
	}
	
	public static String sqlSel(String name,String grade,String c_id,String m_id) {
		System.out.println("查询条件"+name+grade+"**"+c_id+"**"+m_id);
		String sql = "select * from student";
		if(name==null||grade==null||c_id==null||m_id==null) return sql;
		if(!name.isEmpty()||!grade.equals("-1")||!c_id.equals("-1")||!m_id.equals("-1")) {
			sql += " where ";
			if(!name.isEmpty()) sql += "name='"+name+"' and ";
			if(!grade.equals("-1")) sql += "grade="+grade+" and ";
			if(!c_id.equals("-1")) sql += "c_id="+c_id+" and ";
			if(!m_id.equals("-1")) sql += "m_id="+m_id+" and ";
			sql = sql.substring(0, sql.length()-5);
		}
		System.out.println("查询语句为"+sql);
		return sql;
	}
	
	public static String sqlSel(String id) {
		String sql = "select * from student where id="+id;
		System.out.println(sql);
		return sql;
	}
	public static String sqlSel() {
		return "select * from student";
	}
	
	public static String sqlUpd(String id,String name,
	String sex,String grade,String c_id,String m_id,String classs,
	String company,String city,String job,String money,String type) {
		String sql = "update student set ";
		sql += "name='"+name+"'";
		sql += ",sex="+sex;
		sql += ",grade="+grade;
		sql += ",c_id="+c_id;
		sql += ",m_id="+m_id;
		sql += ",classs='"+classs+"'";
		sql += ",company='"+company+"'";
		sql += ",city='"+city+"'";
		sql += ",job='"+job+"'";
		sql += ",money="+money;
		sql += ",type="+type;
		sql += " where id="+id;
		return sql;
	}
	
	public static String sqlIns(String name,
			String sex,String grade,String c_id,String m_id,String classs,
			String company,String city,String job,String money,String type) {
		String sql = "insert into student("
				+ "name,sex,grade,c_id,m_id,classs,company,city,job,money,type) "
				+ "values(";
		sql += "'"+name+"',";
		sql += sex+",";
		sql += grade+",";
		sql += c_id+",";
		sql += m_id+",";
		sql += "'"+classs+"',";
		sql += "'"+company+"',";
		sql += "'"+city+"',";
		sql += "'"+job+"',";
		sql += money+",";
		sql += type+")";
		return sql;
	}
	
	public static String sqlpage(String sql,Integer page,Integer num) {
		if(sql.contains("limit")) {
			sql = sql.substring(0, sql.lastIndexOf('l')-1);
		}
		if(page==0) {
			sql += " limit "+(page*num)+","+num;
		}
		else {
			sql += " limit "+((page-1)*num)+","+num;
		}
		return sql;
	}
	
//	DP.update(Student.class, 
//			Student.sqlUpd(request.getParameter("id")
//					, request.getAttribute("name"), 
//					request.getParameter("sex"),
//					request.getParameter("grade"),
//					request.getParameter("c_id"),
//					request.getParameter("m_id"),
//					request.getParameter("classs"),
//					request.getParameter("company"),
//					request.getParameter("city"),
//					request.getParameter("job"),
//					request.getParameter("money"),
//					request.getParameter("type"))
//			, null);
	@Override
	public String toString() {
		return ""+id+" "+name+" "+sex+" "+grade+" "+c_id
				+" "+m_id+" "+classs+" "+company+" "+city
				+" "+job+" "+money+" "+type;
	}





	/**
	 * @return the id
	 */
	public Integer getId() {
		return id;
	}

	/**
	 * @param id the id to set
	 */
	public void setId(Integer id) {
		this.id = id;
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return the sex
	 */
	public Integer getSex() {
		return sex;
	}

	/**
	 * @param sex the sex to set
	 */
	public void setSex(Integer sex) {
		this.sex = sex;
	}

	/**
	 * @return the grade
	 */
	public Integer getGrade() {
		return grade;
	}

	/**
	 * @param grade the grade to set
	 */
	public void setGrade(Integer grade) {
		this.grade = grade;
	}

	/**
	 * @return the c_id
	 */
	public Integer getC_id() {
		return c_id;
	}

	/**
	 * @param c_id the c_id to set
	 */
	public void setC_id(Integer c_id) {
		this.c_id = c_id;
	}

	/**
	 * @return the m_id
	 */
	public Integer getM_id() {
		return m_id;
	}

	/**
	 * @param m_id the m_id to set
	 */
	public void setM_id(Integer m_id) {
		this.m_id = m_id;
	}

	/**
	 * @return the company
	 */
	public String getCompany() {
		return company;
	}

	/**
	 * @param company the company to set
	 */
	public void setCompany(String company) {
		this.company = company;
	}

	/**
	 * @return the city
	 */
	public String getCity() {
		return city;
	}

	/**
	 * @param city the city to set
	 */
	public void setCity(String city) {
		this.city = city;
	}

	/**
	 * @return the job
	 */
	public String getJob() {
		return job;
	}

	/**
	 * @param job the job to set
	 */
	public void setJob(String job) {
		this.job = job;
	}

	/**
	 * @return the money
	 */
	public Double getMoney() {
		return money;
	}

	/**
	 * @param money the money to set
	 */
	public void setMoney(Double money) {
		this.money = money;
	}

	/**
	 * @return the type
	 */
	public Integer getType() {
		return type;
	}

	/**
	 * @param type the type to set
	 */
	public void setType(Integer type) {
		this.type = type;
	}

	/**
	 * @return the classs
	 */
	public String getClasss() {
		return classs;
	}
	/**
	 * @param classs the classs to set
	 */
	public void setClasss(String classs) {
		this.classs = classs;
	}
	
	
	
	
	
	
}













